<template>
	<view class="pay-page">
		
		<!-- 商品信息 -->
		<view class="shopping-box">
			<view class="shopping-list">
				<view class="shopping-item">
					<view class="shopping-img">
						<image :src="products.thump"></image>
					</view>
					<view class="shopping-info">
						<view class="shopping-hd">
							<view class="shopping-title">{{products.title}}</view>
						</view>
						<view class="shopping-text">{{products.desc}}</view>
					</view>
				</view>
				<view class="shopping-text">{{products.desc}}</view>

			</view>
			<view style="margin-left: 30rpx;">
				<u-form-item label="图片上传" label-width="130" label-position ="top">
					<u-upload :action="action" v-model="fileList" @on-success="uploadSuccess"></u-upload>
				</u-form-item>
				<u-form-item label="备注" prop="remark">
					<u-input v-model="remark" />
				</u-form-item>
			</view>
			
			<view style="width: 50%;height: 100rpx;background: #A4ADB3; display: flex;align-items: center;justify-content: center;
			margin-left: 25%;border-radius: 30rpx;position: fixed;bottom: 100rpx;
			"
				@click="create"
			>
				点击兑换
			</view>
		</view>
		

	</view>
</template>

<script>
	import request from '@/common/request.js';
	export default {
		data() {
			return {
				skuId:"",
				num:0,
				products:{},
				action:"http://egg.aiplaygpt.com/api/common/upload",
				fileList:[],
				remark:""
			}
		},
		computed:{
			sumMomey(){
				let sumPrice = this.products.price;
				
				return sumPrice;
			}
		},
		onLoad(option) {
			
			this.skuId = option.id;
			this.init();
		},
		methods: {
			init(){
				let opt = {
					url : 'api/gashapons/detail',
					method: 'get'
				};
				
				request.httpTokenRequest(opt,{id:this.skuId}).then((res)=>{
					this.products = res.data.data;
				})
			},
			// 向下舍去小数点后两位
			floor(val) {
				return Math.floor(val * 100) / 100;
			},
			uploadSuccess(e){
				console.log(e);
				let url = {
					url:e.data.url
				};
				this.fileList.push(url)
			},
			create(){
				if(!this.skuId){
					uni.showToast({ title:'没有商品可以兑换', icon: 'none' });
					return ;
				}
				if(!this.fileList || this.fileList.length <1)
				{
					uni.showToast({ title:'请上传图片', icon: 'none' });
					return ;
				}
				if(!this.remark)
				{
					uni.showToast({ title:'请输入备注', icon: 'none' });
					return ;
				}
				
				
				let opts2 = {
					url: 'api/gashapons/exchange',
					method: 'post'
				};
				let value = {
					remark:this.remark,
					skuId:this.skuId,
					image:JSON.stringify(this.fileList)
				}
								
				request.httpTokenRequest(opts2,value).then((res)=>{
					if(res.data.code == '1'){
						uni.showToast({ title:res.data.msg, icon: 'none' });
						
						setTimeout(()=>{
							uni.navigateBack({
								delta:1
							})
						},1000)
						return ;
					}else{
						uni.showToast({ title:res.data.msg, icon: 'none' });
						return ;
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	page{
		background: #fff;
	}
	.pay-page {
		padding: 30rpx 30rpx 160rpx 30rpx;
		display: flex;
		flex-direction: column;

		.address-box {
			padding: 20rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 14rpx;
			background: #fff;
		}

		.address-text {
			font-size: 28rpx;
			color: #000;
			margin-left: 10rpx;
		}

		.shopping-box {
			margin-top: 20rpx;
			border-radius: 14rpx;
			display: flex;
			flex-direction: column;
			background: #fff;
			padding: 20rpx 0;
		}

		.lable-title {
			font-size: 32rpx;
			font-weight: 600;
			color: #000;
			padding: 10rpx 24rpx;
			border-bottom: 2rpx solid rgb(248, 248, 248);
		}

		.shopping-list {
			display: flex;
			flex-direction: column;
			padding: 0 24rpx;

		}

		.lable-number {
			font-size: 24rpx;
			color: #999;
			padding-right: 24rpx;
		}

		.shopping-top {
			display: flex;
			align-items: center;
			justify-content: space-between;
		}

		.shopping-item {
			display: flex;
			padding: 20rpx 0;
			border-bottom: 2rpx solid rgb(248, 248, 248);
		}

		.shopping-img {
			height: 400rpx;
			width: 400rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.shopping-info {
			flex: 1;
			margin-left: 20rpx;
			display: flex;
			flex-direction: column;
		}

		.shopping-hd {
			display: flex;
			align-items: center;
			justify-content: space-between;
		}

		.shopping-title {
			flex: 1;

		}

		.shopping-price {
			width: 120rpx;
			display: flex;
			align-items: center;
			justify-content: flex-end;
			color: #000;
			font-size: 28rpx;
			font-weight: 600;
		}

		.shopping-text {
			margin-top: 10rpx;
			font-size: 24rpx;
			color: #999;
		}
	}

	.end-price {
		padding: 24rpx;
		display: flex;
		align-items: center;
		justify-content: flex-end;
	}

	.end-label {
		font-size: 24rpx;
		color: #000;
	}

	.end-number {
		color: rgb(245, 54, 22);
		font-size: 28rpx;
		font-weight: 600;
	}
	.footer-box {
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
		height: 140rpx;
		background: #fff;
		display: flex;
	border-top: 1rpx solid rgb(214, 215, 217);
		.footer-content {
			padding: 24rpx;
			display: flex;
			align-items: center;
			// margin-bottom: 60rpx;
			flex: 1;
		}
	
		.price-box {
			flex: 1;
			display: flex;
			align-items: center;
		}
	
		.price-text {
			display: flex;
			align-items: center;
			color: rgb(245, 54, 22);
			font-weight: 600;
			font-size: 32rpx;
		}
		.price-text2 {
			display: flex;
			align-items: center;
			color: #000;
			font-weight: 600;
			font-size: 32rpx;
		}
	}
	.print-item-entry {
		display: flex;
		align-items: center;
		// flex: 1;
		flex-wrap: wrap;
		justify-content: flex-end;
	}
	.select-box {
		// width: 200rpx;
		display: flex;
		align-items: center;
		background: #CECECE;
		padding: 10rpx 30rpx;
		border-radius: 10rpx;
		margin-left: 20rpx;
		justify-content: center;
	
		.selecet-text {
			color: #000;
			font-size: 30rpx;
		}
	
		.selecet-icon {
			margin-left: 4rpx;
		}
	}
	.cell-left {
		font-size: 24rpx;
		color:#000;
	}
	.cell-list {
		padding: 30rpx 24rpx;
		
	}
</style>